<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function __construct(){      //构造方法
    	parent::__construct();       //先继承父类
	//网站栏目导航
    	$cate = D('category');
    	// $where = $where['parentid=0'];
	    $where['parentid']=0;
    	$cates = $cate->where($where)->select();
    	$this->assign('cates',$cates);

        
        if(I('cate_id')){
            $cateid=I('cate_id');
        }

	//获取当前位置
    	$result = $cate->getparent($cateid);  //getparent()方法在categorymodel里
    	$this->assign('res',$result);

    //获取当前栏目
        if ($cateid) {
            $cateself=$cate->where("cate_id=$cateid")->find();
            $this->assign('cateself',$cateself);
        //获取顶级栏目
            if ($cateself['parentid']!=0) {
                $parentid =$cateself['parentid'];
                $catetop = $cate->where("cate_id=$parentid")->find();
                $this->assign('catetop',$catetop);
            }else{
                $catetop = $cateself;
                $this->assign('catetop',$catetop);
            }
        }
        


    }



}